﻿using System;
using System.Runtime.Caching;

namespace Awaken.Utils.CacheProvider
{
    /// <summary>
    ///     缓存供应
    ///     <para>--------------------------</para>
    ///     <para>@Author: cnalexi@gmail.com</para>
    ///     <para>@Create: 2012/3/21</para>
    /// </summary>
    public interface ICacheProvider
    {
        /// <summary>
        ///     缓存对象
        /// </summary>
        ObjectCache MyCache { get; }

        /// <summary>
        ///     存入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="t"></param>
        void Insert<T>(string key, T t);

        /// <summary>
        ///     存入带规则
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="t"></param>
        /// <param name="policy"></param>
        void Insert<T>(string key, T t, CacheItemPolicy policy);

        /// <summary>
        ///     获取
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        T Get<T>(string key);

        /// <summary>
        ///     获取，如果是初始值则用GETDATA（）数据存入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="GetData"></param>
        /// <returns></returns>
        T Get<T>(string key, Func<T> GetData);

        /// <summary>
        ///     获取，如果是初始值则用GETDATA（）数据存入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="GetData"></param>
        /// <param name="policy"></param>
        /// <returns></returns>
        T Get<T>(string key, Func<T> GetData, CacheItemPolicy policy);

        /// <summary>
        ///     移除缓存项
        /// </summary>
        /// <param name="key"></param>
        void Remove(string key);

        /// <summary>
        ///     缓存重置
        /// </summary>
        void Clear();

        /// <summary>
        ///     更新
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="t"></param>
        void Update<T>(string key, T t);

        /// <summary>
        ///     更新带规则
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="t"></param>
        /// <param name="policy"></param>
        void Update<T>(string key, T t, CacheItemPolicy policy);

        /// <summary>
        ///     查询是否包含此KEY对象
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        bool Contains(string key);
    }
}